# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo1321
# Description:
# Author:       yzl
# Date:         2019-02-08
#-------------------------------------------------------------------------------

"""
# 写文件
f = open('test1.txt','w')
print(f.write('I love '))
print(f.write('python'))
f.close()
"""

"""
# 读文件
f = open('test1.txt','r')
print(f.read())
# 重置文件指针
f.seek(0)
print(f.read(7))
print(f.read(6))
f.close()
"""

# 文件不存在会抛出异常
# try:
#     f = open('test2.txt','r+')
# except Exception as e:
#     print(e)


# 文件不存在则创建此文件
# f = open('test2.txt','a+')
# print(f.write('hello111'))
# f.close()

# 读文件
# f = open('test2.txt','a+')
# print(f.read())
# f.seek(0)
# print(f.read())
# f.close()



try:
    f = open('text3.txt','w+')
    print(f.read())
    f.write('how are you!')
    f.seek(0)
    print(f.read())
except Exception as e:
    print(e)
finally:
    f.close()





